package vericopServer;

import java.util.LinkedList;
import java.util.List;

public class Session {
	
	 private List<Object> _sessionReceivedMessages;
     private Object _lockingObject;

     public Session(int sessionId)
     {
         _sessionReceivedMessages = new LinkedList<Object>();
         _lockingObject = new Object();
     }

     public void addSessionMessage(Object obj)
     {
         synchronized(_lockingObject)
         {
             _sessionReceivedMessages.add(obj);
             _lockingObject.notify();
         }
     }

     public Object getSessionMessage()
     {
         synchronized(_lockingObject)
         {
             if (_sessionReceivedMessages.size() == 0)
             {
                 try {
					_lockingObject.wait();
				} catch (InterruptedException e) {
					return null;
				}                   
             }

             Object obj = _sessionReceivedMessages.remove(0);
             return obj;
         }
     }

}
